#编写一个函数ThreeNumberSum,接收数组array 和数字 targetsum,返回所有array里相加得targetsum的值。
def threeNumberSum(array, targetSum):

    array.sort()
    numbers = []

    for number in range(len(array) - 2):
        
        left = number + 1
        right = len(array) - 1

        while right > left:
            numberSum = array[left] + array[right] + array[number]

            if numberSum == targetSum:
                numbers.append([array[left], array[right], array[number]])
                left += 1
                right -= 1

            elif numberSum > targetSum:
                right -= 1

            elif numberSum < targetSum:
                left += 1

    return numbers

print(threeNumberSum([-1, -2, 3], 0))